package com.leet.code.simple_array;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/25 17:29
 */

public class PivotIndex {
    public int pivotIndex(int[] nums) {
        int sum = 0, leftsum = 0;
        for (int x : nums) sum += x;
        for (int i = 0; i < nums.length; i++) {
            if (leftsum == sum - leftsum - nums[i]) return i;
            leftsum += nums[i];
        }
        return -1;
    }
}
